#ifndef CCMDPARSE2_H
#define CCMDPARSE2_H

#include <QObject>
#include <QDomNode>
#include <QDomElement>
#include <QReadWriteLock>
#include "ttg_ips/cttgipsconnector.h"
#include "locol_ips/clocolips.h"
#include "v2/xml/xml_device_object.h"
#include "clog.h"
#include "cmd_parse/caudiocontrol.h"
#include "cexeccmd.h"
#include "audio/ccommunication.h"

class CCmdParse_v2 : public QObject
{
    Q_OBJECT
public:
    explicit CCmdParse_v2(QObject *parent = 0);
    ~CCmdParse_v2();
	
    QStringList _allDeviceId;

    void runningCheck();
    void projectInit(QString jsonPath);
    bool projectContext(QByteArray xml);

    bool anayseXmlData(QByteArray xmlData);
    QByteArray anayseJsonData(QByteArray jsonData);

    void setDevControl(QDomElement element);
    void getDevControl(QDomElement element);

    void setDevControlJson(QJsonObject element);
    void getDevControlJson(QJsonObject element);

    QString updateVoiceJson(QJsonObject element);
    void updateDevJson(QJsonObject element);
    QString setDevMsg(QJsonObject element);
    int doAudioParse(QByteArray bytes);

    void addDevice2audioControl(Xml_DEVICE_OBJECT *j);

    void setUpKnxObjs();
    void projectDestroy();    

    void refreshStatus();
signals:    
    void s_XmlReport(QByteArray xmlData);
    void s_JsonReport(QString jsonData);
    void s_deviceJsonReport(QString id,QString json);
    void s_updateMode(QString);
    void s_controlCmd(QString);

public slots:
    void doGateWayStateUpdate(int state);
    void doGateWayValueUpdate(void *devObj,QByteArray value,void *userdata);
    void doGateWayValueUpdateDebug(void *devObj,QString value,void *userdata);
    void doRecordUpdate(QString r);
    void doRefreshObject();
    void doStatusTest();

private:
    CTTGIpsConnector *ttgIps;
    CLocolIPS *locolIps;
    QMap<QString,Xml_DEVICE_OBJECT *> _regObjMap;
    QList<Xml_DEVICE_OBJECT *> _listRefresh,_listReadAfterWrite;

    _u8 _addr_buf[2],_data_buf[32];
    QReadWriteLock lock;

    QTimer _refreshTimer,_testStatusTimer;
    QString _recordData;
    CLog *_gLog;

    CAudioControl _audioControl;
    CCommunication _audioCommunicate;

    CExecCmd _execCmd;
};

#endif // CCMDPARSE_H
